﻿using DBUtility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IYAKASAPortal.Statistics
{
    public partial class PrintJCXCHB : System.Web.UI.Page
    {
        private static string strStart { get; set; }
        private static string strEnd { get; set; }

        private static string strSqlst { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            btnSearch_Click(sender, e);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            strStart = txtStart.Text;
            strEnd = txtEnd.Text;
            string strDate = "";

            string strSql = "select ROW_NUMBER() over (order by jcxh) as seqnum,jcxh from(select DISTINCT  jcxh from RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%'";

            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSql += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
                lblDate.Text = DateTime.Parse(strStart).ToLongDateString().ToString() + " - " + DateTime.Parse(strEnd).ToLongDateString().ToString();
            }
            else
            {
                strDate = DbHelper.GetValue("select top 1 jcrq from RESULT_VEHICLE_INFO order by jcrq asc");
                lblDate.Text = DateTime.Parse(strDate).ToLongDateString().ToString() + " - " + DateTime.Now.ToLongDateString().ToString();
            }

            strSql += " )table1";

            DataTable m_dtTable = new DataTable();

            DbHelper.GetTable(strSql, ref m_dtTable);

            rptList.DataSource = m_dtTable;
            rptList.DataBind();

            m_dtTable.Dispose();
        }

        protected string getCJS(string jcxh)
        {
            string strSql = "";
            strSql = "SELECT COUNT(*) FROM (SELECT JCXH FROM RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%' and JCLSH LIKE '%01' and JCXH='" + jcxh + "'";
            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSql += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
            }
            strSql += " )TABLE1";
            return DbHelper.GetValue(strSql);
        }

        protected string getCHGS(string jcxh)
        {
            string strSql = "";
            strSql = "SELECT COUNT(*) FROM (SELECT JCXH FROM RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%' and JCLSH LIKE '%01' AND Z_PD='1' and JCXH='" + jcxh + "'";
            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSql += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
            }
            strSql += " )TABLE1";
            return DbHelper.GetValue(strSql);
        }

        protected string getCHGL(string jcxh)
        {
            float hgl = 0;
            string strSqlsb = "SELECT COUNT(*) FROM (SELECT JCXH FROM RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%' and JCXH='" + jcxh + "'";
            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSqlsb += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
            }
            strSqlsb += " )TABLE1";
            string sb = DbHelper.GetValue(strSqlsb);

            string strSqlsp = "SELECT COUNT(*) FROM (SELECT JCXH FROM RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%' and JCLSH LIKE '%01' AND Z_PD='1' and JCXH='" + jcxh + "'";
            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSqlsp += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
            }
            strSqlsp += " )TABLE1";
            string sp = DbHelper.GetValue(strSqlsp);
            if (int.Parse(sb) != 0)
            {
                hgl = (float.Parse(sp) / float.Parse(sb)) * 100;
            }
            return hgl.ToString("F2") == "0.00" ? "0" : hgl.ToString("F2");
        }

        protected string getYHGS(string jcxh)
        {
            string strSql = "";
            strSql = "SELECT COUNT(*) FROM (SELECT JCXH FROM RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%' and JCLSH LIKE '%02' AND Z_PD='1' and JCXH='" + jcxh + "'";
            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSql += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
            }
            strSql += " )TABLE1";
            return DbHelper.GetValue(strSql);
        }

        protected string getYHGL(string jcxh)
        {
            float hgl = 0;
            string strSqlsb = "SELECT COUNT(*) FROM (SELECT JCXH FROM RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%' and JCXH='" + jcxh + "'";

            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSqlsb += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
            }
            strSqlsb += " )TABLE1";

            string strSqlsp = "SELECT COUNT(*) FROM (SELECT JCXH FROM RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%' and JCLSH LIKE '%02' AND Z_PD='1' and JCXH='" + jcxh + "'";
            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSqlsp += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
            }
            strSqlsp += " )TABLE1";

            string sb = DbHelper.GetValue(strSqlsb);
            string sp = DbHelper.GetValue(strSqlsp);
            if (int.Parse(sb) != 0)
            {
                hgl = (float.Parse(sp) / float.Parse(sb)) * 100;
            }
            return hgl.ToString("F2") == "0.00" ? "0" : hgl.ToString("F2");
        }

        protected string getEHGS(string jcxh)
        {
            string strSql = "";
            strSql = "SELECT COUNT(*) FROM (SELECT JCXH FROM RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%' and JCLSH LIKE '%03' AND Z_PD='1' and JCXH='" + jcxh + "'";
            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSql += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
            }
            strSql += " )TABLE1";
            return DbHelper.GetValue(strSql);
        }

        protected string getEHGL(string jcxh)
        {
            float hgl = 0;
            string strSqlsb = "SELECT COUNT(*) FROM (SELECT JCXH FROM RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%' and JCXH='" + jcxh + "'";
            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSqlsb += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
            }
            strSqlsb += " )TABLE1";

            string strSqlsp = "SELECT COUNT(*) FROM (SELECT JCXH FROM RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%' and JCLSH LIKE '%03' AND Z_PD='1' and JCXH='" + jcxh + "'";
            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSqlsp += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
            }
            strSqlsp += " )TABLE1";

            string sb = DbHelper.GetValue(strSqlsb);
            string sp = DbHelper.GetValue(strSqlsp);

            if (int.Parse(sb) != 0)
            {
                hgl = (float.Parse(sp) / float.Parse(sb)) * 100;
            }
            return hgl.ToString("F2") == "0.00" ? "0" : hgl.ToString("F2");
        }

        protected string getSHGS(string jcxh)
        {
            string strSql = "";
            strSql = "SELECT COUNT(*) FROM (SELECT JCXH FROM RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%' and JCLSH not LIKE '%01' and JCLSH not LIKE '%02' and JCLSH not LIKE '%03'  AND Z_PD='1' and JCXH='" + jcxh + "'";
            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSql += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
            }
            strSql += " )TABLE1";
            return DbHelper.GetValue(strSql);
        }

        protected string getSHGL(string jcxh)
        {
            float hgl = 0;
            string strSqlsb = "SELECT COUNT(*) FROM (SELECT JCXH FROM RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%' and JCXH='" + jcxh + "'";
            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSqlsb += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
            }
            strSqlsb += " )TABLE1";

            string strSqlsp = "SELECT COUNT(*) FROM (SELECT JCXH FROM RESULT_VEHICLE_INFO WHERE JCLSH LIKE 'P%' and JCLSH not LIKE '%01' and JCLSH not LIKE '%02' and JCLSH not LIKE '%03' AND Z_PD='1' and JCXH='" + jcxh + "'";
            if (strStart.Length > 0 && strEnd.Length > 0)
            {
                strSqlsp += " and jcrq between '" + strStart + "' and '" + strEnd + "'";
            }
            strSqlsp += " )TABLE1";

            string sb = DbHelper.GetValue(strSqlsb);
            string sp = DbHelper.GetValue(strSqlsp);

            if (int.Parse(sb) != 0)
            {
                hgl = (float.Parse(sp) / float.Parse(sb)) * 100;
            }
            return hgl.ToString("F2") == "0.00" ? "0" : hgl.ToString("F2");
        }

        protected void btnSearchAll_Click(object sender, EventArgs e)
        {
            txtStart.Text = "";
            txtEnd.Text = "";
            btnSearch_Click(sender, e);
        }

        protected void btnPrint_Click(object sender, EventArgs e)
        {

        }
    }
}